/**********************************************************
 * vcap_buf.h
 *
 *  Copy right (c) 2011, Media Information Systems Inc.
 *
 *  Created on: 2011-11-15
 *      Author: Elvis.zhang
 *     Version: v0.0.0
 *
 *********************************************************/

#ifndef VCAP_BUF_H_
#define VCAP_BUF_H_

typedef enum{
	CAPBUF_STATE_INVALID = 0,
	CAPBUF_STATE_VALID,
}CAPBUF_STATE;

typedef	struct{
	struct	semaphore	mutex;
	void				*buf;
	int					state;
}CAPBUFFER,*PCAPBUFFER;

typedef	struct{
	wait_queue_head_t	hWaitRead;
	int					bWaitRead;
	wait_queue_head_t	hWaitWrite;
	int					bWaitWrite;

	PCAPBUFFER			capBuf;
	int					nBuf;
	int					rIdx;
	int					wIdx;
	int					wIdx_lock;
	int					wIdx_release;
}CAPBUF_Obj,*CAPBUF_Handle;

extern CAPBUF_Handle	CAPBUF_create();
extern void			CAPBUF_delete(CAPBUF_Handle h);

extern void			CAPBUF_setBuf(CAPBUF_Handle h,int nNum,void* ppbuf[]);

extern void*			CAPBUF_LockRead(CAPBUF_Handle h,void* timeout);
extern void*			CAPBUF_LockWrite(CAPBUF_Handle h,void* timeout);

extern int				CAPBUF_UnLockRead(CAPBUF_Handle h);
extern int				CAPBUF_UnLockWrite(CAPBUF_Handle h);
#endif /* VCAP_BUF_H_ */
